//
//  XinchouController.m
//  Ten
//
//  Created by anfuer on 2018/8/17.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "XinchouController.h"
#import "XinchouCell.h"
#import "ZYLAlert.h"
@interface XinchouController ()
{
    NSArray*delivers;
}
@property (weak, nonatomic) IBOutlet UITableView *tbv;
@property (weak, nonatomic) IBOutlet UILabel *lb1;
@property (weak, nonatomic) IBOutlet UIView *hidenView;

@end

@implementation XinchouController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (@available(iOS 11.0, *)){
        _tbv.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        _tbv.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
    }else
    {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
   _tbv.separatorColor=[UIColor clearColor];
    
   
    // Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    if ([WXGStr([FuncPublic GetDefaultInfo:@"token"])empty]) {
        _lb1.text=@"请先登录";
        
        ZYLAlert *zylAlert = [[ZYLAlert alloc] initWithTitle:nil message:@"登录后才能使用"];
        [zylAlert addBtnAlertTitle:@"取消" action:^{
            self.tabBarController.selectedIndex=0;
            
        }];
        [zylAlert addBtnAlertTitle:@"去登录" action:^{
            [MyUtils  IsLongin];
        }];
        
        [zylAlert showAlertWithSender:self];
    }else
    {
        [FuncPublic getData:self parameters:@{@"status":@"0"} RequestUrl:Salaryindex success:^(NSDictionary *acountInfo) {
            _lb1.text=[NSString stringWithFormat:@"￥%@", acountInfo[@"expense"]];
            delivers=acountInfo[@"delivers"];
            _hidenView.hidden=delivers.count;
            
            [_tbv reloadData];
        }];
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)TopBtna:(UIButton *)sender {
    if ([[sender currentTitle]isEqualToString:@"明细"]) {
        [MyUtils collviewSelidex:@"薪资明细" toVc:self andShopInfo:nil];
    }else if ([[sender currentTitle]isEqualToString:@"提  现"])
    {
         [MyUtils collviewSelidex:@"提现列表" toVc:self andShopInfo:nil];
    }else if ([[sender currentTitle]isEqualToString:@"银行卡"])
    {
         [MyUtils collviewSelidex:@"银行卡" toVc:self andShopInfo:nil];
    }
}

#pragma mark 返回分组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return delivers.count;
}

#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    XinchouCell*cell=[XinchouCell CellWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell Cellinit:delivers[indexPath.section]];
    return cell;
}
#pragma mark 设置分组头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section==0?0:10;
}


#pragma mark 设置尾部说明内容高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 130;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    [MyUtils collviewSelidex:@"录用详情" toVc:self andShopInfo:delivers[indexPath.section]];
}
@end
